package com.zhdl;

import com.zhdl.hardware_contact.hardware_common.service.CurrencyCmdSendService;
import com.zhdl.hardware_contact.hardware_web.service.HardwareCurrentService;
import com.zhdl.modules.demo.DCHTProcess.MotorInterface;
import com.zhdl.modules.demo.web.CommonProtocolTestService;
import com.zhdl.modules.process.service.ProjectConfigProcessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.ApplicationPidFileWriter;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.context.WebApplicationContext;

import javax.annotation.Resource;

@Slf4j
@EnableAsync
@EnableScheduling
@SpringBootApplication(scanBasePackages = {"com.zhdl", "com.project"})
public class AppApplication extends SpringBootServletInitializer implements ApplicationRunner {

    @Resource
    private CurrencyCmdSendService currencyCmdSendService;

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(AppApplication.class);
        app.addListeners(new ApplicationPidFileWriter());
        app.run(args);
    }
    @Resource
    private CommonProtocolTestService commonProtocolTestService;

    @Resource
    private ProjectConfigProcessService projectConfigProcessService;

    @Resource
    private HardwareCurrentService hardwareCurrentService;

    @Resource
    private MotorInterface motorInterface;

    @Override
    protected WebApplicationContext run(SpringApplication application) {
        return super.run(application);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return super.configure(builder);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
//        commonProtocolTestService.init();
        currencyCmdSendService.initAllHardware();

        projectConfigProcessService.initProjectConfiguration("动触头");

        hardwareCurrentService.initHardwareCurrent();


    }

}
